import { SphereRegion } from "@sapi-game/gameRegion/gameRegion";
import { DimensionIds } from "@sapi-game/utils/vanila-data";
import { monopolyModule } from "@/monopoly/moudle";
import { MonopolyMainState } from "./mainState";

export class MonopolyCountdownState extends monopolyModule.State {
    private region = new SphereRegion(
        DimensionIds.Overworld,
        { x: -190, y: -38, z: 259 },
        30
    );

    override onEnter(): void {
        this.runner.run(async (r) => {
            r.do(() => {
                this.region.runCommandOnPlayers("title @s title §a5");
                this.region.runCommandOnPlayers(
                    "playsound note.pling @s ~~~ 1 0.5"
                );
            });
            await r.wait(20);
            r.do(() => {
                this.region.runCommandOnPlayers("title @s title §a4");
                this.region.runCommandOnPlayers(
                    "playsound note.pling @s ~~~ 1 0.6"
                );
            });
            await r.wait(20);
            r.do(() => {
                this.region.runCommandOnPlayers("title @s title §63");
                this.region.runCommandOnPlayers(
                    "playsound note.pling @s ~~~ 1 0.7"
                );
            });
            await r.wait(20);
            r.do(() => {
                this.region.runCommandOnPlayers("title @s title §c2");
                this.region.runCommandOnPlayers(
                    "playsound note.pling @s ~~~ 1 0.8"
                );
            });
            await r.wait(20);
            r.do(() => {
                this.region.runCommandOnPlayers("title @s title §41");
                this.region.runCommandOnPlayers(
                    "playsound note.pling @s ~~~ 1 0.9"
                );
            });
            await r.wait(20);
            r.do(() => {
                this.region.runCommandOnPlayers("title @s title §2游戏开始");
                this.region.runCommandOnPlayers(
                    "playsound note.pling @s ~~~ 1 1.0"
                );
            });
            this.transitionTo(MonopolyMainState);
        });
    }
}
